package com.jiayou.Bullet;

import com.jiayou.Tank.Tank2;
import com.jiayou.tools.Constclass;

import java.awt.*;
import java.util.List;

public class Bullet2 extends Model {
    private int sw;
    public Bullet2(){}
    public Bullet2(int x, int y, int speed,int sw) {
        super(x, y, speed);
        this.sw = sw;
    }

    public boolean draw(Graphics graphics, List<com.jiayou.Tank.Model> list)
    {
        boolean b = false;
        Color color = graphics.getColor();
        graphics.setColor(Color.white);
        switch (sw)
        {
            case Constclass.DOWN:
                y+=speed;
                graphics.fill3DRect(x+15,y+40,5,5,false);
                b =bianli(list);
                break;
            case Constclass.UP:
                y-=speed;
                graphics.fill3DRect(x+15,y,5,5,false);
                b =  bianli(list);
                break;
            case Constclass.RIGHT:
                x+=speed;
                graphics.fill3DRect(x+40,y+15,5,5,false);
                b =  bianli(list);
                break;
            case Constclass.LEFT:
                x-=speed;
                graphics.fill3DRect(x,y+15,5,5,false);
                b =  bianli(list);
                break;
        }
        graphics.setColor(color);
        return b;
    }


    @Override
    public Rectangle rec() {
        switch (sw)
        {
            case Constclass.DOWN:
                return new Rectangle((int)x+18,(int)y+40,(int)5,(int)5);
            case Constclass.UP:
                return new Rectangle(x+18,y,5,5);
            case Constclass.RIGHT:
                return new Rectangle(x+40,y+18,5,5);
            case Constclass.LEFT:
                return new Rectangle(x,y+18,5,5);
        }
        return null;
    }


    private boolean bianli(List<com.jiayou.Tank.Model> list)
    {
        for (com.jiayou.Tank.Model model :list)
        {
            if (rec().intersects(model.rec()))
            {
                System.out.println("打死了");
                list.remove(model);
                return true;
            }

        }
        return false;
    }
}
